﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 鼠标画线
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        bool a = false;
        Point pt1 = new Point();
        Point pt2 = new Point();
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            pt1.X = e.X;
            pt1.Y = e.Y;
            a = true;
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (a)
            {
                pt2.X = e.X;
                pt2.Y = e.Y;
                Graphics g = this.CreateGraphics();
                Pen pen = new Pen(Color.Black,2);
                g.DrawLine(pen, pt1, pt2);
            }
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            //Graphics g = this.CreateGraphics();
            //Pen pen = new Pen(Color.Black, 5);
            //g.DrawLine(pen, pt1, pt2);
        }
    }
}
